<template>
	<view class="joker-my-history">
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :up="upOption"
			:fixed="false">
			<view class="my-history-box flex-row justify-between" v-for="item in dataList" @click="openDetail(item.id)">
				<view class="history-box-1">
					<view>{{ item.joker1 }}</view>
					<view class="date">{{ item.create_time }}</view>
				</view>
				<view class="history-box-2">
					<view class="text-ellipsis">{{ item.joker2 }}</view>
					<view class="box1 text-ellipsis">浏览：{{ item.hits }}人</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import jokerDecrypt from '@/common/joker.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				jokerModel: {
					page: 1,
					size: 10
				},
				dataList: [],
				upOption: {
					page: {
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 5, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					empty: {
						tip: '暂无相关数据'
					},
					textNoMore: '到底了'
				}
			}
		},
		methods: {
			upCallback(page) {
				this.jokerModel.page = page.num
				this.jokerModel.size = page.size
				this.getData()
			},
      openDetail(id){
        uni.navigateTo({
					url: '/pages/index/detail/detail?id=' + id + "&t=" + Date.now()
        })
      },
			async getData() {
				uni.showLoading({
					title: '请求中...'
				})
				const res = await this.$api.mySeeLog(this.jokerModel);
				uni.hideLoading()
				if (res.code != 200) return uni.showToast({
					title: res.msg,
					icon: 'none',
					mask: true
				})
				const row = jokerDecrypt(res.data.data, res.data.key)
				const resData = JSON.parse(row).info
				console.log(resData)
				if (resData.data.length > 0) {
					if (this.jokerModel.page === 1) {
						resData.data.map(row=>{
							row.joker1= row.title.split(' ')[0]
							row.joker2= row.title.split(' ')[3]
						})
						this.dataList = resData.data;
					} else {
						this.dataList.push(...resData.data);
					}
					this.mescroll.endBySize(resData.data.length, resData.total);
				} else {
					this.dataList = []
					this.mescroll.endErr();
				}
			},
		}
	}
</script>

<style>

</style>